    //
//  LoadingViewController_iPad.m
//  PokerPlus
//
//  Created by sunrui-MacBook on 11-7-29.
//  Copyright 2011 139.ME. All rights reserved.
//

#import "LoadingViewController_iPad.h"

@interface LoadingViewController_iPad (Private)

- (BOOL)OnConnect;//与大厅(登录服务器)建立连接
- (BOOL)OnLogin;
- (void)OnEnterHall:(SocketEngine *)socket;
@end


@implementation LoadingViewController_iPad

UIView * loadingView;
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	socketLogin = [[AppDelegate sharedDelegate] mainsocket];
	eventLogin = [[AppDelegate sharedDelegate] eventLogin];
	hostIP = [[AppDelegate sharedDelegate] hostName];
	port = [[AppDelegate sharedDelegate] port];
	
	IMP OnEnterHall = [self methodForSelector:@selector(OnEnterHall:)];
	
	[eventLogin AddCmd:hchLogin fun:(CMDFUN)OnEnterHall];
	[eventLogin AddCmd:hhcLoginSuccess fun:(CMDFUN)OnEnterHall];
	loadingView = self.view;
	
}

- (void)viewDidAppear:(BOOL)animated{
	[super viewDidAppear:animated];
	//与大厅(登录服务器)建立连接
	if (![self OnConnect]) {
		NSLog(@"已经建立连接!");
		[[AppDelegate sharedDelegate] cmdGetUserInfo:socketLogin];
		
	}
	[self OnLogin];
	NSLog(@"Loading appear");
	
}

- (void)viewDidDisappear:(BOOL)animated{
	NSLog(@"loading disappear");
	[super viewDidDisappear:animated];
	self.view.alpha = 1.0f;
	
	
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}


- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end


#pragma mark LoadingViewController_iPad-Private
@implementation LoadingViewController_iPad (Private)

- (BOOL)OnConnect
{
	return [socketLogin connect:hostIP port:port];
}

- (BOOL)OnLogin
{	
	NSString * userName = [[NSUserDefaults standardUserDefaults] objectForKey:USERNAME];	
	if (userName == nil) {
		_isGuest = YES;
	}
	else {
		_isGuest = NO;
	}
	
	//以Guest身份
	if (_isGuest) {			
		
	}
	else {
		//以注册会员身份
				
	}	
	
	return YES;
}

- (void)OnEnterHall:(SocketEngine *)socket{
	//[[AppDelegate sharedDelegate] performSelector:@selector(ServerConnected:) withObject:loadingView afterDelay:1.0f];
	[[AppDelegate sharedDelegate] ServerConnected:loadingView];
	//[[AppDelegate sharedDelegate] cmdGetRoomSort:socket];
	
}




@end
